package edu.fiu.cis.personalize.server.graph;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import edu.fiu.cis.personalize.server.graph.store.NodeEdges;

//A Group object has two attributes "groupName" and "groupDescription"
@SuppressWarnings("serial")
public class Group extends Node implements Serializable {

	private String description;
	private Set<Integer> members = new HashSet<Integer>();
	
	public void setDescription(String desctiption) {
		this.description = desctiption;
	}
	
	public String getDescription() {
		return description;
	}
	
	/**
	 * 
	 * @param name
	 */
	public Group(int id, String name) {
		super(id,name);
	}

	/**
	 * 
	 * @return The group description
	 */
	public String getGroupDescription() {
		return getStringKey();
	}

	public String toString() {
		return getStringKey();
	}

	@Override
	public NodeType getType() {
		return NodeType.GROUP;
	}
	
	public void addMember(User u){
		synchronized (members) {
			members.add(u.getId());
		}
	}

	public boolean hasMember(User u) {
		return members.contains(u.getId());
	}
	
	public Set<Integer> getMembers() {
		return members;
	}

	public static Group create(int id, String gname, NodeEdges nodeEdges,
			double rank, Set<Integer> membersSet, String desc) {
		Group g = new Group(id, gname);
		g.edges = nodeEdges;
		g.rank = rank;
		g.members = membersSet;
		g.description = desc;
		return g;
	}
	
}